"""
人脸相关Schema定义
定义API请求和响应的数据模型
"""
from typing import Optional, List, Dict, Any
from pydantic import Field
from schemas.common import BaseSchema


# ==================== 请求Schema ====================

class FaceAddRequest(BaseSchema):
    """人脸添加请求"""
    person_id: str = Field(..., description="人员ID", min_length=1, max_length=64)
    person_name: str = Field(..., description="人员姓名", min_length=1, max_length=100)
    image: str = Field(..., description="图片base64编码")
    meta_info: Optional[Dict[str, Any]] = Field(default=None, description="扩展信息")


class FaceCompareRequest(BaseSchema):
    """人脸比对请求"""
    image_a: str = Field(..., description="图片A的base64编码")
    image_b: str = Field(..., description="图片B的base64编码")


class FaceSearchRequest(BaseSchema):
    """人脸识别请求"""
    image: str = Field(..., description="待识别图片的base64编码")
    top_k: int = Field(default=5, description="返回前K个结果", ge=1, le=20)
    threshold: float = Field(default=0.7, description="相似度阈值", ge=0.0, le=1.0)


class FaceDetectRequest(BaseSchema):
    """人脸检测请求"""
    image: str = Field(..., description="图片base64编码")


class FaceDeleteRequest(BaseSchema):
    """人脸删除请求"""
    face_id: str = Field(..., description="人脸ID")


# ==================== 响应Schema ====================

class FaceRect(BaseSchema):
    """人脸框坐标"""
    x: int = Field(..., description="左上角X坐标")
    y: int = Field(..., description="左上角Y坐标")
    width: int = Field(..., description="宽度")
    height: int = Field(..., description="高度")


class FaceAddResponse(BaseSchema):
    """人脸添加响应"""
    face_id: str = Field(..., description="人脸ID")
    person_id: str = Field(..., description="人员ID")
    person_name: str = Field(..., description="人员姓名")
    quality: float = Field(..., description="人脸质量分数 0-1")
    face_rect: FaceRect = Field(..., description="人脸框坐标")


class FaceCompareResponse(BaseSchema):
    """人脸比对响应"""
    similarity: float = Field(..., description="相似度分数 0-1")
    is_match: bool = Field(..., description="是否匹配")
    threshold: float = Field(..., description="匹配阈值")


class FaceSearchResult(BaseSchema):
    """人脸识别单个结果"""
    face_id: str = Field(..., description="人脸ID")
    person_id: str = Field(..., description="人员ID")
    person_name: str = Field(..., description="人员姓名")
    similarity: float = Field(..., description="相似度 0-1")


class FaceSearchResponse(BaseSchema):
    """人脸识别响应"""
    face_count: int = Field(..., description="检测到的人脸数量")
    results: List[FaceSearchResult] = Field(..., description="识别结果列表")


class FaceDetectResult(BaseSchema):
    """人脸检测单个结果"""
    face_rect: FaceRect = Field(..., description="人脸框坐标")
    landmarks: List[List[float]] = Field(..., description="关键点坐标")
    quality: float = Field(..., description="质量分数")
    angle: Optional[float] = Field(None, description="人脸角度")


class FaceDetectResponse(BaseSchema):
    """人脸检测响应"""
    face_count: int = Field(..., description="检测到的人脸数量")
    faces: List[FaceDetectResult] = Field(..., description="人脸信息列表")


class FaceInfo(BaseSchema):
    """人脸信息"""
    face_id: str = Field(..., description="人脸ID")
    person_id: str = Field(..., description="人员ID")
    person_name: str = Field(..., description="人员姓名")
    quality_score: float = Field(..., description="质量分数")
    is_active: bool = Field(..., description="是否启用")
    created_at: str = Field(..., description="创建时间")
    meta_info: Optional[Dict[str, Any]] = Field(None, description="扩展信息")
